const isPalindrome = (x) => {
    return x.toString().split('').reverse().join('') === x.toString();
}

var a = 123454321;
var b = 12345;

console.log(isPalindrome(a));
console.log(isPalindrome(b));

/** 进阶：不将整数转为字符串来解决这个问题吗 */
const isPalindrome2 = (x) => {
    if(x < 0 || (x % 10 === 0 && x != 0))
        return false;
    let reversed = 0;
    while(x > reversed) {
        reversed = reversed * 10 + x % 10;
        x = Math.floor(x / 10);
    }
    return x === reversed || x === Math.floor(reversed / 10);
}

var c = -1;
console.log(isPalindrome2(a));
console.log(isPalindrome2(c));